package com.framework.core.api.feign.factory;

import com.framework.common.Enums.FrameworkErrorCodeEnum;
import com.framework.common.domain.R;
import com.framework.core.api.feign.RemoteThirdUserService;
import com.framework.core.api.request.ThirdUserInfoReq;
import com.framework.core.api.response.ThirdUserInfoQueryRes;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author zhoubb
 * @version V1.0
 * @Date 2020/4/30 23:36
 * @since JDK 1.8
 */
@Slf4j
@Component
public class RemoteThirdUserFallbackFactory implements FallbackFactory<RemoteThirdUserService> {

    @Override
    public RemoteThirdUserService create(Throwable throwable) {
        log.error(throwable.getMessage());
        return new RemoteThirdUserService() {

            @Override
            public R registerThirdUser(ThirdUserInfoReq thirdUserInfoReq) {
                return R.error(FrameworkErrorCodeEnum.NET_ERR);
            }

            @Override
            public ThirdUserInfoQueryRes getOrRegThirdUserInfoByOpenId(ThirdUserInfoReq thirdUserInfoReq) {
                RemoteThirdUserFallbackFactory.log.warn("fallback,causedBy:"+ throwable);
                return null;
            }

            @Override
            public ThirdUserInfoQueryRes getThirdUserInfoByOpenId(String openId) {
                return null;
            }
        };
    }
}
